$(document).ready(function() {
    // 模拟规则数据
    var rules = [
        { id: 1, expression: '表达式1' },
        { id: 2, expression: '表达式2' },
        // 更多规则
    ];

    // 页面加载完成后渲染表格
    renderRules(rules);

    function renderRules(rules) {
        var tableBody = $('#rule-table-body');
        tableBody.empty();  // 清空表格内容

        $.each(rules, function(index, rule) {
            var row = '<tr data-rule-id="' + rule.id + '">';
            row += '<td>' + rule.id + '</td>';
            row += '<td>' + rule.expression + '</td>';
            row += '<td><button class="delete-btn">删除</button></td>';
            row += '</tr>';
            tableBody.append(row);
        });

        // 绑定删除按钮的点击事件
        $('.delete-btn').click(function() {
            var ruleId = $(this).closest('tr').data('rule-id');
            deleteRule(ruleId);
        });
    }

    function deleteRule(ruleId) {
        // 模拟删除操作
        rules = rules.filter(function(rule) {
            return rule.id !== ruleId;
        });

        renderRules(rules);  // 删除后重新渲染表格
    }
});
